package com.cloud.api.myenum;

import cn.hutool.extra.spring.SpringUtil;
import com.baomidou.mybatisplus.annotation.IEnum;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;

import java.util.Locale;

public enum LeaseCycleEnum implements IEnum<Integer> {

    MOON(0,"enum.cycle.moon"),
    YEAR(1,"enum.cycle.year");


    LeaseCycleEnum(Integer value, String desc) {
        this.value = value;
        this.desc = desc;
    }

    private Integer value;

    private String desc;


    private static MessageSource messageSource = SpringUtil.getBean(MessageSource.class);


    @Override
    public Integer getValue() {
        return this.value;
    }


    public void setDesc(String desc) {
        this.desc = desc;
    }


    public static String getInstance(String value) {
        Locale locale = LocaleContextHolder.getLocale();
        String desc = null;
        for (LeaseCycleEnum a : LeaseCycleEnum.values()){
            if (a.value == Integer.parseInt(value)){
                desc = a.desc;
            }
        }
        return messageSource.getMessage(desc, null,"translate error", locale);
    }
}
